package cs2340.todolist.JUnit;

import android.app.Activity;
import android.test.ActivityInstrumentationTestCase2;
import cs2340.todolist.model.account_management.AccountManager;
import cs2340.todolist.model.account_management.AccountManager.AccountManagementMessage;
import cs2340.todolist.model.sqlite_database.ToDoItemDataSource;
import cs2340.todolist.model.sqlite_database.UserAccountDataSource;
import cs2340.todolist.splash.Splash;

/**
 * this tests the method tryToCreateAccount() of AccountManager
 * precondition: email address must be in expected format: xxxx@xxxx.com | .net | .org
 *  	username must be between 3 and 14 characters long, special characters allowed
 *  	password must be between 3 and 14 characters long, special characters allowed
 *  	password and retypePassword must match
 * postcondition: user account is created and added to the database
 * @author Wslaughter
 *
 */
public class TestAddUser extends ActivityInstrumentationTestCase2<Splash> {
	public TestAddUser(){
		super("cs2340.todolist.splash", Splash.class);
	}
	
	AccountManager am;
	Activity activity;
	public static final String ACCOUNT_CREATED_MESSAGE		= "Account Successfully Created!\nReturning to login screen!";
	public static final String PASSWORD_NOT_MATCH_MESSAGE 	= "Passwords do not match!";
	public static final String INVALID_USERNAME_MESSAGE 	= "Invalid Username.\nUsernames must be greater than " + 3 + " and less than " + 14 + " characters long!";
	public static final String INVALID_PASSWORD_MESSAGE		= "Invalid Password.\nPasswords must be greater than " + 3 + " and less than " + 14 + " characters long!";
	public static final String INVALID_EMAIL				= "Invalid Email. \nThe email you provided does not look like an email!";
	public static final String USERNAME_IN_USE_MESSAGE		= "Username already in use. Sorry!";
	public static final String USERNAME_PASSWORD_NOT_MATCH_MESSAGE = "Username and/or password did not match.";
	
	public void setUp() throws Exception {
		super.setUp();
		activity = getActivity();
		am = new AccountManager(activity);
	}
	
	public void testCreateUser(){
		AccountManagementMessage duplicate = am.tryToCreateAccount("Will","email@gmail.com","uname","password","password");
		AccountManagementMessage duplicate1 = am.tryToCreateAccount("Will","email@gmail.com","uname","password","password");
		AccountManagementMessage invName = am.tryToCreateAccount("1asdfjkl;","email@gmail.com","uname1","password","password");
		AccountManagementMessage invEmail = am.tryToCreateAccount("Will","asdfjkl;","uname1","password","password");
		AccountManagementMessage invUname = am.tryToCreateAccount("Will","email@gmail.com","1asdfjkl;","password","password");
		AccountManagementMessage shrtUname = am.tryToCreateAccount("Will", "email@gmail.com", "un", "password", "password");
		AccountManagementMessage lngUname = am.tryToCreateAccount("Will","email@gmail.com","thisusernameshouldbefartoolongtobeacceptedbyoursoftware","password","password");
		AccountManagementMessage shrtPass = am.tryToCreateAccount("Will","email@gmail.com","uname2","ps","ps");
		AccountManagementMessage lngPass = am.tryToCreateAccount("Will","email@gmail.com","uname3","thispasswordisfartoolongtobeacceptedbyoursoftware","thispasswordisfartoolongtobeacceptedbyoursoftware");
		AccountManagementMessage passNoMatch = am.tryToCreateAccount("Will","email@gmail.com","uname5","password","passssss");
		
		
		junit.framework.Assert.assertEquals("Test if adding an item meeting all preconditions succeeds",ACCOUNT_CREATED_MESSAGE,duplicate);
		junit.framework.Assert.assertEquals("Test if adding a duplicate users returns appropriate message",USERNAME_IN_USE_MESSAGE,duplicate1);
		junit.framework.Assert.assertEquals("Test if odd characters in the name field still creates an account",ACCOUNT_CREATED_MESSAGE,invName);
		junit.framework.Assert.assertEquals("Test if garbage typed in email field handles correctly",INVALID_EMAIL,invEmail);
		junit.framework.Assert.assertEquals("test if garbage username still creates an account",ACCOUNT_CREATED_MESSAGE,invUname);
		junit.framework.Assert.assertEquals("Test if a short username fails",INVALID_USERNAME_MESSAGE,shrtUname);
		junit.framework.Assert.assertEquals("Test if a long username fails",INVALID_USERNAME_MESSAGE,lngUname);
		junit.framework.Assert.assertEquals("Test if a short password fails",INVALID_PASSWORD_MESSAGE,shrtPass);
		junit.framework.Assert.assertEquals("Test if a long password fails",INVALID_PASSWORD_MESSAGE,lngPass);
		junit.framework.Assert.assertEquals("Test if non matching passwords fail", PASSWORD_NOT_MATCH_MESSAGE,passNoMatch);
		
		
		
	}

}
